home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / sep91.zip / 9N09125A < prev    next >
Text File  |  1991-05-13  |  2KB  |  72 lines

  1. /* Listing 2 */
  2.  
  3. void filled_circle( int x_pos, int y_pos,
  4.                     int radius, int fillcolor);
  5. int colormax;
  6.  
  7.  
  8. /************************************************/
  9.  
  10. void generate_circles()
  11.  
  12. /* this function draws a series of circles at random */
  13. /* positions, each one after the first touching the  */
  14. /* nearest circle that has been previously drawn     */
  15.  
  16. {
  17.    int xmax, ymax, x_pos, y_pos, radius;
  18.    randomize();   /* initialize the random numbers */
  19.    xmax = getmaxx(); /* maximum x and y positions  */
  20.    ymax = getmaxy(); /* that can be displayed      */
  21.  
  22.    rmax = max( xmax, ymax)/2;
  23.           /* divisor of 2 can be changed to allow */
  24.           /* different maximum radii              */
  25.  
  26.    colormax = getmaxcolor();
  27.  
  28.    /* select random position and draw first circle */
  29.  
  30.    x_pos = rand() % xmax;
  31.    y_pos = rand() % ymax;
  32.    radius = rand() % rmax;
  33.    c[0].x = x_pos;
  34.    c[0].y = y_pos;
  35.    c[0].r = radius;
  36.    filled_circle( x_pos, y_pos, radius,
  37.                       rand() % colormax);
  38.  
  39.    /* select and draw remaining randomly placed circles */
  40.    /* each tangent to the nearest previously drawn      */
  41.    /* circle                                            */
  42.  
  43.    for ( N = 1; N <= MAX_CIRCLES; N++)
  44.        {
  45.        do
  46.            {
  47.            exit_if_kbhit();
  48.            x_pos = rand() % xmax;
  49.            y_pos = rand() % ymax;
  50.            radius = new_radius( x_pos, y_pos);
  51.            } while (radius <= 0);
  52.        filled_circle( x_pos, y_pos, radius,
  53.                       rand() % colormax + 1);
  54.        c[N].x = x_pos;
  55.        c[N].y = y_pos;
  56.        c[N].r = radius;
  57.        }
  58. }
  59.  
  60. /************************************************/
  61.  
  62. void filled_circle( int x_pos, int y_pos,
  63.                     int radius, int fillcolor)
  64.  
  65. /* draws a circle filled with the specified color */
  66.  
  67. {
  68.    circle( x_pos, y_pos, radius);
  69.    setfillstyle( SOLID_FILL, fillcolor);
  70.    floodfill( x_pos, y_pos, getcolor());
  71. }
  72.